/*
 * Powered By [pkuWx]
 * Web Site: http://www.wuxi.ss.pku.edu.cn
 * Since 2015 - 2015
 */

package cn.edu.pku.wxlib.usertobookborrow.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.pku.wxlib.book.model.Book;
import cn.edu.pku.wxlib.book.service.BookManager;
import cn.edu.pku.wxlib.book.vo.query.BookQuery;
import cn.edu.pku.wxlib.booksku.model.Booksku;
import cn.edu.pku.wxlib.booksku.service.BookskuManager;
import cn.edu.pku.wxlib.booksku.vo.query.BookskuQuery;
import cn.edu.pku.wxlib.borrowtracing.model.Borrowtracing;
import cn.edu.pku.wxlib.borrowtracing.service.BorrowtracingManager;
import cn.edu.pku.wxlib.borrowtracing.vo.query.BorrowtracingQuery;
import cn.edu.pku.wxlib.common.authority.Login;
import cn.edu.pku.wxlib.common.dict.BookBorrowStatusEnum;
import cn.edu.pku.wxlib.common.util.LibUtil;
import cn.edu.pku.wxlib.user.model.User;
import cn.edu.pku.wxlib.user.service.UserManager;
import cn.edu.pku.wxlib.user.vo.query.UserQuery;
import cn.edu.pku.wxlib.usertobookborrow.model.Usertobookborrow;
import cn.edu.pku.wxlib.usertobookborrow.service.UsertobookborrowManager;
import cn.edu.pku.wxlib.usertobookborrow.vo.query.UsertobookborrowQuery;
import cn.edu.pku.wxlib.vo.query.BookBorrowFullQuery;
import cn.edu.pku.wxlib.vo.query.BookskuFullQuery;
import cn.edu.pku.wxlib.vo.response.BookBorrowFull;
import cn.edu.pku.wxlib.vo.response.BookskuFull;
import cn.edu.pku.wxlib.vo.response.BorrowtracingFull;
import cn.edu.pku.wxlib.vo.sessionmodel.SessionUser;
import cn.org.rapid_framework.web.scope.Flash;
import javacommon.base.BaseRestSpringController;
import javacommon.page.Page;

/**
 * @version 1.0
 * @since 1.0
 */

@Controller
@RequestMapping("/usertobookborrow")
public class UsertobookborrowController extends BaseRestSpringController<Usertobookborrow, java.lang.Integer> {
	// 默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null;

	private final String LIST_ACTION = "redirect:/usertobookborrow";

	private UsertobookborrowManager usertobookborrowManager;

	public void setUsertobookborrowManager(UsertobookborrowManager manager) {
		this.usertobookborrowManager = manager;
	}

	private BookskuManager bookskuManager;

	public void setBookskuManager(BookskuManager bookskuManager) {
		this.bookskuManager = bookskuManager;
	}

	private UserManager userManager;

	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	private BookManager bookManager;

	public void setBookManager(BookManager bookManager) {
		this.bookManager = bookManager;
	}

	private BorrowtracingManager borrowtracingManager;

	public void setBorrowtracingManager(BorrowtracingManager borrowtracingManager) {
		this.borrowtracingManager = borrowtracingManager;
	}

	@InitBinder
	public void initBinder(WebDataBinder binder) {
		binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
	}

	/** 增加了@ModelAttribute的方法可以在本controller方法调用前执行,可以存放一些共享变量,如枚举值,或是一些初始化操作 */
	@ModelAttribute
	public void init(ModelMap model) {
	}
	
	private BookBorrowFullQuery setQuery(Integer state, BookBorrowFullQuery query) {
		List<Integer> states = new ArrayList<Integer>();
		query.setSkustate(null);
		query.setState(null);
		query.setSkustate(null);
		if (state != null) {
			if (state == 1) { // 查找可外借
				query.setIsRenew(0);
				query.setSkustate(2); // 在架
			} else if (state == 2) { // 查找可续借
				query.setIsRenew(0);
				query.setState(1); // 即状态为“在借”的图书
				query.setSkustate(3);
			} else if (state == 3) { // 已续借
				query.setIsRenew(0);
				query.setState(2);
				query.setSkustate(4);
			} else {
				state--;
				query.setState(state);
				query.setIsRenew(1);
			}
		} else { // 查询全部
			query.setIsRenew(0);
			states.add(2);
			states.add(3);
			states.add(4);
			states.add(5);
			query.setSkustates(states);
		}
		return query;
	}
	/** 查询今天不同状态的图书数量  */
	@Login
	@RequestMapping(value = "/count", method = RequestMethod.POST)
	public @ResponseBody
		Map<String, Object> countByStatus(@RequestBody BookBorrowFullQuery query,ModelMap model,HttpServletRequest request, 
				HttpServletResponse response) {
		Map<String, Object> json = new HashMap<String, Object>();
		List<Integer> states = new ArrayList<Integer>();
//		areadictManager.addAccessibleAreas2Query(query,query.getAreaId(),request);
		List<Usertobookborrow> countList = new ArrayList<Usertobookborrow>();
		for(int i = 1; i < 7; i++) {
			query = this.setQuery(i, query);
			List<Usertobookborrow> list = this.usertobookborrowManager.countByStates(query);
			if (list != null && list.size() > 0)
				countList.add(list.get(0));
		}
		json.put("data",countList);
			
		return json;
	}

	/**
	 * 查询不同状态的图书
	 */
	@Login
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> listByStates(@RequestBody BookBorrowFullQuery query, ModelMap model,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> json = new HashMap<String, Object>();
		List<Integer> states = new ArrayList<Integer>();
		// sku 1非外借，2在架，3在借，4续借，5已预约，6下架，7报废，8丢失
		// 页面query 0 全部，1可借，2可续借，3已续借，4已还，5欠款，6已丢失
		// 1在借，2续借，3已还，4欠款，5丢失
		if (query.getState() != null) {
			int state = query.getState();
			if (state == 1) { // 查找可外借
				query.setIsRenew(0);
				query.setState(null);
				query.setSkustate(2); // 在架
			} else if (state == 2) { // 查找可续借
				query.setIsRenew(0);
				query.setState(1); // 即状态为“在借”的图书
				query.setSkustate(3);
			} else if (state == 3) { // 已续借
				query.setIsRenew(0);
				query.setState(2);
				query.setSkustate(4);
			} else {
				state--;
				query.setState(state);
				query.setIsRenew(1);
			}
		} else { // 查询全部
			query.setIsRenew(0);
			states.add(2);
			states.add(3);
			states.add(4);
			states.add(5);
			query.setSkustates(states);
		}

		Page page = this.usertobookborrowManager.findFull(query);
		List<BookBorrowFull> list = page.getResult();

		json.put("resultCode", "100");
		json.put("data", list);
		json.put("data", page.getResult());
		json.put("currentPage", page.getThisPageNumber());
		json.put("pageNum", page.getPageSize());
		json.put("total", page.getTotalCount());
		return json;
	}

//	/**
//	 * 查询已还图书
//	 */
//	@Login
//	@RequestMapping(value = "/returnlist", method = RequestMethod.POST)
//	public @ResponseBody Map<String, Object> returnList(@RequestBody BookBorrowFullQuery query, ModelMap model,
//			HttpServletRequest request, HttpServletResponse response) {
//		Map<String, Object> json = new HashMap<String, Object>();
//		List<Integer> states = new ArrayList<Integer>();
//		// sku 1非外借，2在架，3在借，4续借，5已预约，6下架，7报废，8丢失
//		query.setIsRenew(1);
//		query.setState(3); // 即状态为“已还”的图书
//
//		Page page = this.usertobookborrowManager.findFull(query);
//		List<BookBorrowFull> list = page.getResult();
//
//		json.put("resultCode", "100");
//		json.put("data", list);
//		json.put("data", page.getResult());
//		json.put("currentPage", page.getThisPageNumber());
//		json.put("pageNum", page.getPageSize());
//		json.put("total", page.getTotalCount());
//		return json;
//	}

	/** 查询流通详情 */
	@Login
	@RequestMapping(value = "/{borrowid}/returntracing")
	public @ResponseBody Map<String, Object> returntracing(ModelMap model, @PathVariable java.lang.Integer borrowid, HttpServletRequest request) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();

		HttpSession session = request.getSession();
		SessionUser user = (SessionUser) session.getAttribute("login");

		BorrowtracingQuery query = new BorrowtracingQuery();
		query.setUserToBookBorrowId(borrowid);

		List<BorrowtracingFull> list = this.borrowtracingManager.findFullPage(query).getResult();
		if (list != null && list.size() > 0) {
			json.put("resultCode", "100");
			json.put("list",list);
		} else {
			json.put("resultCode", "101"); // 未找到流通记录
		}
		return json;
	}

	/** 图书外借 @PathVariable*/
	@Login
	@RequestMapping(value = "/{id}/{userName}/s_borrow")
	public @ResponseBody
	Map<String, Object> bookBorrow(ModelMap model, @PathVariable java.lang.Integer id, @PathVariable java.lang.String userName, HttpServletRequest request) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		
		HttpSession session = request.getSession();
		SessionUser user = (SessionUser) session.getAttribute("login");

		BookskuFullQuery query = new BookskuFullQuery();
		query.setBookSkuid(id);
		List<BookskuFull> list = this.bookskuManager.findFull(query).getResult();
		// 该sku存在，且对应的图书存在
		if(list != null && list.size() > 0) {
			BookskuFull bookskuFull = list.get(0);
			
			BookskuQuery bookskuQuery = new BookskuQuery();
			bookskuQuery.setBookSkuid(id);
			List<Booksku> bookskuList = this.bookskuManager.findAllByQuery(bookskuQuery);
			Booksku booksku = bookskuList.get(0);
			
			BookQuery bookQuery = new BookQuery();
			bookQuery.setBookId(booksku.getBookId());
			List<Book> bookList = this.bookManager.findAllByQuery(bookQuery);
			Book book = bookList.get(0);
			
			UserQuery userQuery = new UserQuery();
			userQuery.setUserName(userName);
			List<User> userList = this.userManager.findAllByQuery(userQuery);
			if (userList != null && userList.size() > 0) {
				User borrowuser = userList.get(0);
				
				// 更改sku状态
				booksku.setState(3);
				this.bookskuManager.update(booksku);
				// 更改book可借阅数量
				int lendnumber = book.getLendTotalNumber();
				lendnumber--;
				book.setLendTotalNumber(lendnumber);
				this.bookManager.update(book);
				// 新增借阅记录
				Usertobookborrow usertobookborrow = new Usertobookborrow();
				usertobookborrow.setBookSkuid(id);
				Date date = new Date();
				usertobookborrow.setBorrowTime(date);
				usertobookborrow.setShouldReturnTime(LibUtil.calculateEndDate(date, 30));
				usertobookborrow.setState(1);
				usertobookborrow.setIsRenew(0);
				usertobookborrow.setUserId(borrowuser.getUserId());
				this.usertobookborrowManager.save(usertobookborrow);
				// 新增操作记录
				Borrowtracing borrowtracing = new Borrowtracing();
				borrowtracing.setAdminId(user.getUserId());
				borrowtracing.setOperateTime(new Date());
				borrowtracing.setOperateType(1);
				borrowtracing.setUserToBookBorrowId(usertobookborrow.getUserToBookBorrowId());
				this.borrowtracingManager.save(borrowtracing);
				
				json.put("resultCode", "100");
				json.put("skustate", 3);
				json.put("bookName", book.getBookName());
				json.put("userId", borrowuser.getUserId());
				
			} else {
				json.put("resultCode", "101"); //未找到用户
			}
		} else {
			json.put("resultCode", "102"); // 未找到图书
		}
		return json;
	}

	/** 续借 */
	@Login
	@RequestMapping(value = "/{id}/{userId}/s_reborrow")
	public @ResponseBody Map<String, Object> bookreBorrow(ModelMap model, @PathVariable java.lang.Integer id,
			@PathVariable java.lang.Integer userId, HttpServletRequest request) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();

		HttpSession session = request.getSession();
		SessionUser user = (SessionUser) session.getAttribute("login"); // 管理员

		BookBorrowFullQuery query = new BookBorrowFullQuery();
		query.setBookSkuid(id);
		query.setUserId(userId);
		// sku 1非外借，2在架，3在借，4续借，5已预约，6下架，7报废，8丢失
		// bookborrow1在借，2续借，3已还，4欠款，5丢失
		query.setSkustate(3);
		query.setState(1);
		query.setIsRenew(0);

		List<BookBorrowFull> list = this.usertobookborrowManager.findFull(query).getResult();
		// 存在借阅记录，且对应的图书存在
		if (list != null && list.size() > 0) {
			BookBorrowFull bookBorrowFull = list.get(0);

			BookskuQuery bookskuQuery = new BookskuQuery();
			bookskuQuery.setBookSkuid(id);
			List<Booksku> bookskuList = this.bookskuManager.findAllByQuery(bookskuQuery);
			Booksku booksku = bookskuList.get(0);

			User borrowuser = this.userManager.getById(userId);
			if (borrowuser != null) {
				// 更改sku状态
				booksku.setState(4);
				this.bookskuManager.update(booksku);
				// 新增借阅记录
				Usertobookborrow usertobookborrow = this.usertobookborrowManager
						.getById(bookBorrowFull.getUserToBookBorrowId());
				usertobookborrow.setState(2);
				usertobookborrow
						.setShouldReturnTime(LibUtil.calculateEndDate(usertobookborrow.getShouldReturnTime(), 30));
				this.usertobookborrowManager.update(usertobookborrow);
				// 新增操作记录
				Borrowtracing borrowtracing = new Borrowtracing();
				borrowtracing.setAdminId(user.getUserId());
				borrowtracing.setOperateTime(new Date());
				borrowtracing.setOperateType(2);
				borrowtracing.setUserToBookBorrowId(usertobookborrow.getUserToBookBorrowId());
				this.borrowtracingManager.save(borrowtracing);

				json.put("resultCode", "100");
				json.put("skustate", 4);
				json.put("bookName", null);
				json.put("userId", userId);

			} else {
				json.put("resultCode", "101"); // 未找到用户
			}
		} else {
			json.put("resultCode", "102"); // 未找到图书
		}
		return json;
	}

	/** 归还 */
	@Login
	@RequestMapping(value = "/{id}/{userId}/s_return")
	public @ResponseBody Map<String, Object> bookReturn(ModelMap model, @PathVariable java.lang.Integer id,
			@PathVariable java.lang.Integer userId, HttpServletRequest request) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();

		HttpSession session = request.getSession();
		SessionUser user = (SessionUser) session.getAttribute("login"); // 管理员

		BookBorrowFullQuery query = new BookBorrowFullQuery();
		List<Integer> skustates = new ArrayList<Integer>();
		skustates.add(3);
		skustates.add(4);
		query.setBookSkuid(id);
		query.setUserId(userId);
		query.setIsRenew(0);
		// sku 1非外借，2在架，3在借，4续借，5已预约，6下架，7报废，8丢失
		// bookborrow1在借，2续借，3已还，4欠款，5丢失
		query.setSkustates(skustates);
		List<Integer> states = new ArrayList<Integer>();
		states.add(1);
		states.add(2);
		query.setStates(states);

		List<BookBorrowFull> list = this.usertobookborrowManager.findFull(query).getResult();
		// 存在借阅记录，且对应的图书存在
		if (list != null && list.size() > 0) {
			BookBorrowFull bookBorrowFull = list.get(0);

			BookskuQuery bookskuQuery = new BookskuQuery();
			bookskuQuery.setBookSkuid(id);
			List<Booksku> bookskuList = this.bookskuManager.findAllByQuery(bookskuQuery);
			Booksku booksku = bookskuList.get(0);

			BookQuery bookQuery = new BookQuery();
			bookQuery.setBookId(booksku.getBookId());
			List<Book> bookList = this.bookManager.findAllByQuery(bookQuery);
			Book book = bookList.get(0);

			User borrowuser = this.userManager.getById(userId);
			if (borrowuser != null) {
				// 更改sku状态，改为在架
				booksku.setState(2);
				this.bookskuManager.update(booksku);
				// 更改book可借阅数量
				int lendNumber = book.getLendTotalNumber();
				lendNumber++;
				book.setLendTotalNumber(lendNumber);
				this.bookManager.update(book);
				// 新增借阅记录
				Usertobookborrow usertobookborrow = this.usertobookborrowManager
						.getById(bookBorrowFull.getUserToBookBorrowId());
				usertobookborrow.setState(3);
				usertobookborrow.setReturnTime(new Date());
				usertobookborrow.setIsRenew(1);
				this.usertobookborrowManager.update(usertobookborrow);
				// 新增操作记录
				Borrowtracing borrowtracing = new Borrowtracing();
				borrowtracing.setAdminId(user.getUserId());
				borrowtracing.setOperateTime(new Date());
				borrowtracing.setOperateType(3);
				borrowtracing.setUserToBookBorrowId(usertobookborrow.getUserToBookBorrowId());
				this.borrowtracingManager.save(borrowtracing);

				json.put("resultCode", "100");
				json.put("skustate", 2);
				json.put("bookName", book.getBookName());
				json.put("userId", null);
			} else {
				json.put("resultCode", "101"); // 未找到用户
			}
		} else {
			json.put("resultCode", "102"); // 未找到图书
		}
		return json;
	}

	/** 丢失 */
	@Login
	@RequestMapping(value = "/{id}/{userId}/s_lost")
	public @ResponseBody Map<String, Object> bookLost(ModelMap model, @PathVariable java.lang.Integer id,
			@PathVariable java.lang.Integer userId, HttpServletRequest request) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();

		HttpSession session = request.getSession();
		SessionUser user = (SessionUser) session.getAttribute("login"); // 管理员

		BookBorrowFullQuery query = new BookBorrowFullQuery();
		List<Integer> skustates = new ArrayList<Integer>();
		skustates.add(3);
		skustates.add(4);
		query.setBookSkuid(id);
		query.setUserId(userId);
		query.setIsRenew(0);
		// sku 1非外借，2在架，3在借，4续借，5已预约，6下架，7报废，8丢失
		// bookborrow1在借，2续借，3已还，4欠款，5丢失
		query.setSkustates(skustates);
		List<Integer> states = new ArrayList<Integer>();
		states.add(1);
		states.add(2);
		query.setStates(states);

		List<BookBorrowFull> list = this.usertobookborrowManager.findFull(query).getResult();
		// 存在借阅记录，且对应的图书存在
		if (list != null && list.size() > 0) {
			BookBorrowFull bookBorrowFull = list.get(0);

			BookskuQuery bookskuQuery = new BookskuQuery();
			bookskuQuery.setBookSkuid(id);
			List<Booksku> bookskuList = this.bookskuManager.findAllByQuery(bookskuQuery);
			Booksku booksku = bookskuList.get(0);

			BookQuery bookQuery = new BookQuery();
			bookQuery.setBookId(booksku.getBookId());
			List<Book> bookList = this.bookManager.findAllByQuery(bookQuery);
			Book book = bookList.get(0);

			User borrowuser = this.userManager.getById(userId);
			if (borrowuser != null) {
				// 更改sku状态，改为丢失
				booksku.setState(8);
				this.bookskuManager.update(booksku);
				// 更改book可借阅数量
				int lendNumber = book.getLendTotalNumber();
				lendNumber--;
				int storageNumber = book.getStorageTotalNumber();
				storageNumber--;
				book.setLendTotalNumber(lendNumber);
				book.setStorageTotalNumber(storageNumber);
				this.bookManager.update(book);
				// 新增借阅记录
				Usertobookborrow usertobookborrow = this.usertobookborrowManager
						.getById(bookBorrowFull.getUserToBookBorrowId());
				usertobookborrow.setState(5);
				usertobookborrow.setIsRenew(1);
				usertobookborrow.setReturnTime(new Date()); // 丢失时间
				this.usertobookborrowManager.update(usertobookborrow);
				// 新增操作记录
				Borrowtracing borrowtracing = new Borrowtracing();
				borrowtracing.setAdminId(user.getUserId());
				borrowtracing.setOperateTime(new Date());
				borrowtracing.setOperateType(4);
				borrowtracing.setUserToBookBorrowId(usertobookborrow.getUserToBookBorrowId());
				this.borrowtracingManager.save(borrowtracing);

				json.put("resultCode", "100");
				json.put("skustate", 8);
				json.put("bookName", book.getBookName());
				json.put("userId", null);
			} else {
				json.put("resultCode", "101"); // 未找到用户
			}
		} else {
			json.put("resultCode", "102"); // 未找到图书
		}
		return json;
	}

	/** 列表 */
	@Login
	@RequestMapping
	public String index(ModelMap model, UsertobookborrowQuery query, HttpServletRequest request,
			HttpServletResponse response) {
		Page page = this.usertobookborrowManager.findPage(query);

		model.addAllAttributes(toModelMap(page, query));
		return "/usertobookborrow/index";
	}

	/** 显示 */
	@Login
	@RequestMapping(value = "/{id}")
	public String show(ModelMap model, @PathVariable java.lang.Integer id) throws Exception {
		Usertobookborrow usertobookborrow = (Usertobookborrow) usertobookborrowManager.getById(id);
		model.addAttribute("usertobookborrow", usertobookborrow);
		return "/usertobookborrow/show";
	}

	/** 进入新增 */
	@Login
	@RequestMapping(value = "/new")
	public String _new(ModelMap model, Usertobookborrow usertobookborrow, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		model.addAttribute("usertobookborrow", usertobookborrow);
		return "/usertobookborrow/new";
	}

	/** 保存新增 */
	@Login
	@RequestMapping(method = RequestMethod.POST)
	public String create(ModelMap model, @Valid Usertobookborrow usertobookborrow, BindingResult errors,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		if (errors.hasErrors()) {
			return "/usertobookborrow/new";
		}

		usertobookborrowManager.save(usertobookborrow);
		Flash.current().success(CREATED_SUCCESS);
		return LIST_ACTION;
	}

	/** 编辑 */
	@Login
	@RequestMapping(value = "/{id}/edit")
	public String edit(ModelMap model, @PathVariable java.lang.Integer id) throws Exception {
		Usertobookborrow usertobookborrow = (Usertobookborrow) usertobookborrowManager.getById(id);
		model.addAttribute("usertobookborrow", usertobookborrow);
		return "/usertobookborrow/edit";
	}

	/** 保存更新 */
	@Login
	@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
	public String update(ModelMap model, @PathVariable java.lang.Integer id, @Valid Usertobookborrow usertobookborrow,
			BindingResult errors, HttpServletRequest request, HttpServletResponse response) throws Exception {
		if (errors.hasErrors()) {
			return "/usertobookborrow/edit";
		}

		usertobookborrowManager.update(usertobookborrow);
		Flash.current().success(UPDATE_SUCCESS);
		return LIST_ACTION;
	}

	/** 删除 */
	@Login
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public String delete(ModelMap model, @PathVariable java.lang.Integer id) {
		usertobookborrowManager.removeById(id);
		Flash.current().success(DELETE_SUCCESS);
		return LIST_ACTION;
	}

	/** 批量删除 */
	@Login
	@RequestMapping(method = RequestMethod.DELETE)
	public String batchDelete(ModelMap model, @RequestParam("items") java.lang.Integer[] items) {
		for (int i = 0; i < items.length; i++) {
			usertobookborrowManager.removeById(items[i]);
		}
		Flash.current().success(DELETE_SUCCESS);
		return LIST_ACTION;
	}

}
